package com.lin.activity;

import java.util.ArrayList;

import com.lin.fragments.PersonalDetailCardCallHistoryFragment;
import com.lin.fragments.PersonalDetailCardMSMAndCALLFragment;
import com.lin.fragments.SuperFriendDynamicFragment;
import com.lin.utils.Session;
import com.lin.utils.Session.ResultReceiver;
import com.lin.views.ListViewForFriendShare;
import com.lin.views.MyFragmentAdapter;
import com.yunfeng.supercall.R;
import com.yunfeng.supercall.activity.BaseActivity;
import com.yunfeng.supercall.activity.ShareActivity;
import com.yunfeng.supercall.bean.Constants;
import com.yunfeng.supercall.bean.FriendsShareBean;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.Animation.AnimationListener;
import android.widget.FrameLayout;
import android.widget.TextView;

public class FriendsShareDynamicActivity extends FragmentActivity implements Constants, OnClickListener, OnPageChangeListener, AnimationListener{

	private int mOtherId;
	
	View mView1;
	View mView2;
	
	TextView mTextView1;
	TextView mTextView2;
	private ViewPager mViewPager;
	boolean isFromClick = false;
	boolean isAnimationPreceeding = false;
	int mPrecPage = 0;
	Animation mAnimationRight;
	Animation mAnimationLeft;

	private FrameLayout mFrameLayoutMore;
	private FrameLayout mFrameLayoutBack;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_friends_dynamic);
		mView1 =  findViewById(R.id.view1);
		mView2 =  findViewById(R.id.view2);
		mViewPager = (ViewPager) findViewById(R.id.mainViewPager);
		mTextView1 = (TextView) findViewById(R.id.textView1);
		mTextView2 = (TextView) findViewById(R.id.textView2);
		mFrameLayoutMore = (FrameLayout) findViewById(R.id.framelayout_more);
		mFrameLayoutBack = (FrameLayout) findViewById(R.id.framelayout_back);
		
		mFrameLayoutBack.setOnClickListener(this);
		mFrameLayoutMore.setOnClickListener(this);
		mTextView1.setOnClickListener(this);
		mTextView2.setOnClickListener(this);

		mFrameLayoutMore.setVisibility(View.GONE);
		mOtherId = getIntent().getIntExtra(KEY_DATA, 0);
		
		mAnimationRight = AnimationUtils.loadAnimation(getApplicationContext(),
				R.anim.underbar_move_right);
		mAnimationLeft = AnimationUtils.loadAnimation(getApplicationContext(),
				R.anim.underbar_move_left);
		
		mAnimationRight.setAnimationListener(this);
		mAnimationLeft.setAnimationListener(this);
/*		
		if (mOtherId == BaseActivity.getUser(getApplicationContext()).getUserid()) {
//			title.setText(R.string.my_share);
		} else if (mOtherId == -3) {
//			title.setText(R.string.enterprise_share);
		} else if (mOtherId == -2) {
//			title.setText(R.string.focused_share);
		} else if (mOtherId == -1) {
//			title.setText(R.string.fans_share);
		}*/
		
		
		SuperFriendDynamicFragment mSuperFriendDynamicFansFragment1 = new SuperFriendDynamicFragment();
		SuperFriendDynamicFragment mSuperFriendDynamicFansFragment2 = new SuperFriendDynamicFragment();

		Bundle bundle = new Bundle();
		bundle.putInt(KEY_DATA, -2);
		mSuperFriendDynamicFansFragment1.setArguments(bundle);
		
		Bundle bundle2 = new Bundle();
		bundle2.putInt(KEY_DATA, -1);
		mSuperFriendDynamicFansFragment2.setArguments(bundle2);
//		bundle.putParcelable(KEY_DATA, value)
//		mSuperFriendDynamicFansFragment.setArguments();
		ArrayList<Fragment> mFragments1 = new ArrayList<Fragment>();
		mFragments1.add(mSuperFriendDynamicFansFragment1);
		mFragments1.add(mSuperFriendDynamicFansFragment2);
		MyFragmentAdapter mFragmentAdapter = new MyFragmentAdapter(getSupportFragmentManager(),
				mFragments1);
		
		mViewPager.setAdapter(mFragmentAdapter);
		mViewPager.setOnPageChangeListener(this);
	}

	@Override
	public void onClick(View view) {
		// TODO Auto-generated method stub
		if(mTextView1 == view) {
//			isFromClick = true;
			mViewPager.setCurrentItem(0);
		} else if(mTextView2 == view) {
//			isFromClick = true;
			mViewPager.setCurrentItem(1);
		} else if(mFrameLayoutBack == view) {
			finish();
		} else if(mFrameLayoutMore == view) {
			Intent intent = new Intent(this, ShareActivity.class);
			startActivity(intent);
		}
	}

	@Override
	public void onPageScrollStateChanged(int arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onPageScrolled(int arg0, float arg1, int arg2) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onPageSelected(int page) {
		// TODO Auto-generated method stub

		if(isFromClick == false) {
			mView1.setVisibility(View.INVISIBLE);
			mView2.setVisibility(View.INVISIBLE);
			if(page > mPrecPage) {  //往右
				if(page == 1 && isAnimationPreceeding == false) 
					mView1.startAnimation(mAnimationRight);
				else if(page == 2 && isAnimationPreceeding == false) 
					mView2.startAnimation(mAnimationRight);
				mPrecPage = page;
			} else if(page < mPrecPage) {  //往左
				if(page == 0 && isAnimationPreceeding == false) 
					mView2.startAnimation(mAnimationLeft);
				mPrecPage = page; 
			}
		}
		if(page == 0) {
			mTextView1.setTextColor(getResources().getColor(R.color.base_orange));
			mTextView2.setTextColor(getResources().getColor(R.color.text_title_sliding_dark_black));
			//			mView1.setVisibility(View.VISIBLE);
			//			mView2.setVisibility(View.INVISIBLE);
			//			mView3.setVisibility(View.INVISIBLE);




		} else if(page == 1) {
			
			mTextView1.setTextColor(getResources().getColor(R.color.text_title_sliding_dark_black));
			mTextView2.setTextColor(getResources().getColor(R.color.base_orange));
		} 
		if(isFromClick == true) {
			if(page == 0) {
				mView1.setVisibility(View.VISIBLE);
				mView2.setVisibility(View.INVISIBLE);
			} else if(page == 1) {
				mView1.setVisibility(View.INVISIBLE);
				mView2.setVisibility(View.VISIBLE);
			}
		}
		isFromClick = false;
	}

	@Override
	public void onAnimationEnd(Animation arg0) {
		// TODO Auto-generated method stub
		if(mPrecPage == 0) {
			mView1.setVisibility(View.VISIBLE);
			mView2.setVisibility(View.INVISIBLE);
		} else if(mPrecPage == 1) {
			mView1.setVisibility(View.INVISIBLE);
			mView2.setVisibility(View.VISIBLE);
		}
		isAnimationPreceeding = false;

	}

	@Override
	public void onAnimationRepeat(Animation arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onAnimationStart(Animation arg0) {
		// TODO Auto-generated method stub
		
	}

	
	
	
	
}